package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebDetailDao;
import ysq.xyg.model.WebDetail;
import ysq.xyg.service.WebDetailService;

import javax.annotation.Resource;
import java.util.List;


@Service("webDetailService")
public class WebDetailServiceImpl extends BaseServiceImpl<WebDetail> implements WebDetailService {

    @Resource
    private WebDetailDao webDetailDao;
    @Autowired
    public void setpictureDao(WebDetailDao webDetailDao) {
        this.baseDao = webDetailDao;
    }

    @Override
    public PageInfo<WebDetail> page(WebDetail webDetail, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy(" create_time desc");
        return new PageInfo<WebDetail>(webDetailDao.listLeft(webDetail));
    }

    @Override
    public List<WebDetail> list(WebDetail webDetail) {
        // 通用Example查询
        Example example = new Example(WebDetail.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webDetail.getType())) {
            criteria.andEqualTo("type", webDetail.getType());
        }
        if (StringUtils.isNotEmpty(webDetail.getPhone())) {
            criteria.andLike("phone", "%"+webDetail.getPhone()+"%");
        }
        example.setOrderByClause(" create_time desc");
        List<WebDetail> list = webDetailDao.selectByExample(example);
        return list;
    }
}
